package top.viya.hello2.redis.str;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import top.viya.hello2.redis.common.Data;

import java.time.LocalDateTime;
import java.util.Date;

//@Component
public class StrApplicationRunner2 implements ApplicationRunner {

    @Resource(name = "stringRedisTemplate")
    private RedisTemplate<String, String> stringRedisTemplate;

    @Resource(name = "jsonRedisTemplate")
    private RedisTemplate<String, Object> jsonRedisTemplate;

    @Resource
    private ObjectMapper objectMapper;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        jsonRedisTemplate.opsForValue().set("k2-1:json", new Data(1L, "test1", 1.1, LocalDateTime.now(), new Date()));
        Data d1 = objectMapper.readValue(stringRedisTemplate.opsForValue().get("k2-1:json"),Data.class);
        System.out.println(d1);

    }
}
